<!DOCTYPE HTML PUBLIC "-//ORA//DTD CD HTML 3.2//EN">
<HTML>
<HEAD>
<TITLE>[Chapter 18] The java.awt Package</TITLE>
<META NAME="author" CONTENT="David Flanagan">
<META NAME="date" CONTENT="Thu Jul 31 16:09:12 1997">
<META NAME="form" CONTENT="html">
<META NAME="metadata" CONTENT="dublincore.0.1">
<META NAME="objecttype" CONTENT="book part">
<META NAME="otheragent" CONTENT="gmat dbtohtml">
<META NAME="publisher" CONTENT="O'Reilly &amp; Associates, Inc.">
<META NAME="source" CONTENT="SGML">
<META NAME="subject" CONTENT="Java">
<META NAME="title" CONTENT="Java in a Nutshell">
<META HTTP-EQUIV="Content-Script-Type" CONTENT="text/javascript">
</HEAD>
<body vlink="#551a8b" alink="#ff0000" text="#000000" bgcolor="#FFFFFF" link="#0000ee">
<script language='JavaScript'>
<!--
if (location.replace) {
 location.replace ('ch18_js.htm');
}
// -->
</script>

<DIV CLASS=htmlnav>
<H1><a href='index.htm'><IMG SRC="gifs/smbanner.gif"
     ALT="Java in a Nutshell" border=0></a></H1>
<table width=515 border=0 cellpadding=0 cellspacing=0>
<tr>
<td width=172 align=left valign=top><A HREF="ch17_04.htm"><IMG SRC="gifs/txtpreva.gif" ALT="Previous" border=0></A></td>
<td width=171 align=center valign=top><B><FONT FACE="ARIEL,HELVETICA,HELV,SANSERIF" SIZE="-1">Chapter 18</FONT></B></TD>
<td width=172 align=right valign=top><A HREF="ch18_02.htm"><IMG SRC="gifs/txtnexta.gif" ALT="Next" border=0></A></td>
</tr>
</table>

&nbsp;
<hr align=left width=515>
</DIV>
<H1 CLASS=chapter><A CLASS="TITLE" NAME="JNUT2-CH-18">18. The java.awt Package</A></H1>

<DIV CLASS=htmltoc>

<p>
<b>Contents:</b><br>
<a href='ch18_02.htm'>java.awt.AWTEvent (JDK 1.1)</a><br>
<a href='ch18_03.htm'>java.awt.AWTEventMulticaster (JDK 1.1)</a><br>
<a href='ch18_04.htm'>java.awt.AWTException (JDK 1.0)</a><br>
<a href='ch18_05.htm'>java.awt.Adjustable (JDK 1.1)</a><br>
<a href='ch18_06.htm'>java.awt.BorderLayout (JDK 1.0)</a><br>
<a href='ch18_07.htm'>java.awt.Button (JDK 1.0)</a><br>
<a href='ch18_08.htm'>java.awt.Canvas (JDK 1.0)</a><br>
<a href='ch18_09.htm'>java.awt.CardLayout (JDK 1.0)</a><br>
<a href='ch18_10.htm'>java.awt.Checkbox (JDK 1.0)</a><br>
<a href='ch18_11.htm'>java.awt.CheckboxGroup (JDK 1.0)</a><br>
<a href='ch18_12.htm'>java.awt.CheckboxMenuItem (JDK 1.0)</a><br>
<a href='ch18_13.htm'>java.awt.Choice (JDK 1.0)</a><br>
<a href='ch18_14.htm'>java.awt.Color (JDK 1.0)</a><br>
<a href='ch18_15.htm'>java.awt.Component (JDK 1.0)</a><br>
<a href='ch18_16.htm'>java.awt.Container (JDK 1.0)</a><br>
<a href='ch18_17.htm'>java.awt.Cursor (JDK 1.1)</a><br>
<a href='ch18_18.htm'>java.awt.Dialog (JDK 1.0)</a><br>
<a href='ch18_19.htm'>java.awt.Dimension (JDK 1.0)</a><br>
<a href='ch18_20.htm'>java.awt.Event (JDK 1.0)</a><br>
<a href='ch18_21.htm'>java.awt.EventQueue (JDK 1.1)</a><br>
<a href='ch18_22.htm'>java.awt.FileDialog (JDK 1.0)</a><br>
<a href='ch18_23.htm'>java.awt.FlowLayout (JDK 1.0)</a><br>
<a href='ch18_24.htm'>java.awt.Font (JDK 1.0)</a><br>
<a href='ch18_25.htm'>java.awt.FontMetrics (JDK 1.0)</a><br>
<a href='ch18_26.htm'>java.awt.Frame (JDK 1.0)</a><br>
<a href='ch18_27.htm'>java.awt.Graphics (JDK 1.0)</a><br>
<a href='ch18_28.htm'>java.awt.GridBagConstraints (JDK 1.0)</a><br>
<a href='ch18_29.htm'>java.awt.GridBagLayout (JDK 1.0)</a><br>
<a href='ch18_30.htm'>java.awt.GridLayout (JDK 1.0)</a><br>
<a href='ch18_31.htm'>java.awt.IllegalComponentStateException (JDK 1.1)</a><br>
<a href='ch18_32.htm'>java.awt.Image (JDK 1.0)</a><br>
<a href='ch18_33.htm'>java.awt.Insets (JDK 1.0)</a><br>
<a href='ch18_34.htm'>java.awt.ItemSelectable (JDK 1.1)</a><br>
<a href='ch18_35.htm'>java.awt.Label (JDK 1.0)</a><br>
<a href='ch18_36.htm'>java.awt.LayoutManager (JDK 1.0)</a><br>
<a href='ch18_37.htm'>java.awt.LayoutManager2 (JDK 1.1)</a><br>
<a href='ch18_38.htm'>java.awt.List (JDK 1.0)</a><br>
<a href='ch18_39.htm'>java.awt.MediaTracker (JDK 1.0)</a><br>
<a href='ch18_40.htm'>java.awt.Menu (JDK 1.0)</a><br>
<a href='ch18_41.htm'>java.awt.MenuBar (JDK 1.0)</a><br>
<a href='ch18_42.htm'>java.awt.MenuComponent (JDK 1.0)</a><br>
<a href='ch18_43.htm'>java.awt.MenuContainer (JDK 1.0)</a><br>
<a href='ch18_44.htm'>java.awt.MenuItem (JDK 1.0)</a><br>
<a href='ch18_45.htm'>java.awt.MenuShortcut (JDK 1.1)</a><br>
<a href='ch18_46.htm'>java.awt.Panel (JDK 1.0)</a><br>
<a href='ch18_47.htm'>java.awt.Point (JDK 1.0)</a><br>
<a href='ch18_48.htm'>java.awt.Polygon (JDK 1.0)</a><br>
<a href='ch18_49.htm'>java.awt.PopupMenu (JDK 1.1)</a><br>
<a href='ch18_50.htm'>java.awt.PrintGraphics (JDK 1.1)</a><br>
<a href='ch18_51.htm'>java.awt.PrintJob (JDK 1.1)</a><br>
<a href='ch18_52.htm'>java.awt.Rectangle (JDK 1.0)</a><br>
<a href='ch18_53.htm'>java.awt.ScrollPane (JDK 1.1)</a><br>
<a href='ch18_54.htm'>java.awt.Scrollbar (JDK 1.0)</a><br>
<a href='ch18_55.htm'>java.awt.Shape (JDK 1.1)</a><br>
<a href='ch18_56.htm'>java.awt.SystemColor (JDK 1.1)</a><br>
<a href='ch18_57.htm'>java.awt.TextArea (JDK 1.0)</a><br>
<a href='ch18_58.htm'>java.awt.TextComponent (JDK 1.0)</a><br>
<a href='ch18_59.htm'>java.awt.TextField (JDK 1.0)</a><br>
<a href='ch18_60.htm'>java.awt.Toolkit (JDK 1.0)</a><br>
<a href='ch18_61.htm'>java.awt.Window (JDK 1.0)</a><br>
<p>
<p>
</DIV>

<P CLASS=para>
<A NAME="CH18.GRAPHICAL.US1"></A><A NAME="CH18.JAVA.AWT.PAC1"></A><A NAME="CH18.WINDOWS-JAVA1"></A>The <tt CLASS=literal>java.awt</tt> package is the Abstract Windowing
Toolkit.  The classes of this package may be roughly divided
into three categories (see
<A HREF="ch18_01.htm#JNUT2-CH-18-FIG-1">Figure 18.1</A>
and
<A HREF="ch18_01.htm#JNUT2-CH-18-FIG-2">Figure 18.2</A>).

<P>
<UL CLASS=itemizedlist>
<li CLASS=listitem>Graphics: These classes define colors, fonts, images,
polygons, and so forth.

<P>
<li CLASS=listitem>Components: These classes are GUI (graphical user
interface) components such as buttons, menus, lists, and
dialog boxes.

<P>
<li CLASS=listitem>Layout Managers: These classes control the layout of
components within their container objects.

<P>
</UL>
<P CLASS=para>
Note that separate packages, <tt CLASS=literal>java.awt.datatransfer</tt>,
<tt CLASS=literal>java.awt.event</tt>, and <tt CLASS=literal>java.awt.image</tt>, contain
classes for cut-and-paste, event handling, and image
manipulation.

<DIV CLASS=figure>
<h4 CLASS=figure><A CLASS="TITLE" NAME="JNUT2-CH-18-FIG-1">Figure 18.1: Graphics, event, and exception classes of the java.awt package</A></h4>


<p>
<img align=middle src="./figs/jn2_1801.gif" alt="[Graphic: Figure 18-1]" width=464 height=663 border=0>

</DIV>

<P CLASS=para>
In the first category of classes, <tt CLASS=literal>Graphics</tt> is
probably the most important.  This class defines methods for
doing line and text drawing and image painting.  It relies
on other classes such as <tt CLASS=literal>Color</tt>, <tt CLASS=literal>Font</tt>,
<tt CLASS=literal>Image</tt>, and <tt CLASS=literal>Polygon</tt>.  <tt CLASS=literal>Image</tt> is itself
an important class, used in many places in <tt CLASS=literal>java.awt</tt>
and throughout the related package <tt CLASS=literal>java.awt.image</tt>.
<tt CLASS=literal>Event</tt> is another important class that describes a
user or window system event that has occurred.  In Java 1.1,
<tt CLASS=literal>Event</tt> is superseded by the <tt CLASS=literal>AWTEvent</tt> class.

<P CLASS=para>
<tt CLASS=literal>Component</tt> and <tt CLASS=literal>MenuComponent</tt> are root classes
in the second category of <tt CLASS=literal>java.awt</tt> classes.  Their
subclasses are GUI components that can appear in interfaces
and menus.  The <tt CLASS=literal>Container</tt> class is one that contains
components and arranges them visually.  You add components
to a container with the <tt CLASS=literal>add()</tt> method and specify a
layout manager for the container with the
<tt CLASS=literal>setLayout()</tt> method.

<P CLASS=para>
There are three commonly used <tt CLASS=literal>Container</tt> subclasses.
<tt CLASS=literal>Frame</tt> is a toplevel window that can contain a
menu bar and have a custom cursor and an icon.
<tt CLASS=literal>Dialog</tt> is a dialog window.  <tt CLASS=literal>Panel</tt> is a
container that does not have its own window--it is contained
within some other container.

<P CLASS=para>
The third category of <tt CLASS=literal>java.awt</tt> classes is the layout
managers.  The subclasses of <tt CLASS=literal>LayoutManager</tt> are
responsible for arranging the <tt CLASS=literal>Component</tt> objects
contained within a specified <tt CLASS=literal>Container</tt>.
<tt CLASS=literal>GridBagLayout</tt>, <tt CLASS=literal>BorderLayout</tt>, and
<tt CLASS=literal>GridLayout</tt> are probably the most useful of these
layout managers.

<P CLASS=para>
See <A HREF="ch08_01.htm">Chapter 8, <i>New AWT Features</i></A>, for
examples of using some of the new Java 1.1 features of this package.

<DIV CLASS=figure>
<h4 CLASS=figure><A CLASS="TITLE" NAME="JNUT2-CH-18-FIG-2">Figure 18.2: Component and layout classes of the java.awt package</A></h4>


<p>
<img align=middle src="./figs/jn2_1802.gif" alt="[Graphic: Figure 18-2]" width=464 height=611 border=0>

</DIV>

<DIV CLASS=sect1>
<h2 CLASS=sect1><A CLASS="TITLE" NAME="JNUT2-CH-18-SECT-1">18.1 java.awt.AWTError (JDK 1.0)</A></h2>

<DIV CLASS=sect2>
<h3 CLASS=sect2><A CLASS="TITLE" NAME="JNUT2-CH-18-SECT-1.1"></A></h3>
</DIV>

<P CLASS=para>
Signals that an error has occurred in the
<tt CLASS=literal>java.awt</tt> package.

<DIV CLASS=screen>
<P>
<PRE>
public class <tt CLASS=literal>AWTError</tt> extends Error {
    // <tt CLASS=literal>Public Constructor</tt>
            public <tt CLASS=literal>AWTError</tt>(String <tt CLASS=literal>msg</tt>);
}
</PRE>
</DIV>

</DIV>

<DIV CLASS=sect2>
<h3 CLASS=sect2><A CLASS="TITLE" NAME="JNUT2-CH-18-SECT-1.2">Hierarchy:</A></h3>

<P CLASS=para>
<tt CLASS=literal>Object->Throwable(Serializable)->Error->AWTError</tt>

</DIV>

</DIV>


<DIV CLASS=htmlnav>

<P>
<HR align=left width=515>
<table width=515 border=0 cellpadding=0 cellspacing=0>
<tr>
<td width=172 align=left valign=top><A HREF="ch17_04.htm"><IMG SRC="gifs/txtpreva.gif" ALT="Previous" border=0></A></td>
<td width=171 align=center valign=top><a href="index.htm"><img src='gifs/txthome.gif' border=0 alt='Home'></a></td>
<td width=172 align=right valign=top><A HREF="ch18_02.htm"><IMG SRC="gifs/txtnexta.gif" ALT="Next" border=0></A></td>
</tr>
<tr>
<td width=172 align=left valign=top>java.applet.AudioClip (JDK 1.0)</td>
<td width=171 align=center valign=top><a href="index/idx_0.htm"><img src='gifs/index.gif' alt='Book Index' border=0></a></td>
<td width=172 align=right valign=top>java.awt.AWTEvent (JDK 1.1)</td>
</tr>
</table>
<hr align=left width=515>

<IMG SRC="gifs/smnavbar.gif" USEMAP="#map" BORDER=0> 
<MAP NAME="map"> 
<AREA SHAPE=RECT COORDS="0,0,108,15" HREF="../javanut/index.htm"
alt="Java in a Nutshell"> 
<AREA SHAPE=RECT COORDS="109,0,200,15" HREF="../langref/index.htm" 
alt="Java Language Reference"> 
<AREA SHAPE=RECT COORDS="203,0,290,15" HREF="../awt/index.htm" 
alt="Java AWT"> 
<AREA SHAPE=RECT COORDS="291,0,419,15" HREF="../fclass/index.htm" 
alt="Java Fundamental Classes"> 
<AREA SHAPE=RECT COORDS="421,0,514,15" HREF="../exp/index.htm" 
alt="Exploring Java"> 
</MAP>
</DIV>

</BODY>
</HTML>
